﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vtron.HipcConfigurationTools.Core;
using Vtron.HipcConfigurationTools.Domain;

namespace Vtron.HipcConfigurationTools.Test
{
    /// <summary>
    /// 编码盒API接口测试
    /// </summary>
    [TestClass]
    public class EncodedAPIUnitTest
    {
        [TestInitialize]
        public void Init()
        {
            Utils.IP = "10.4.1.173";
            Utils.PORT = 5001;
        }

        /// <summary>
        /// 消息		选择信号源
        /// ID	请求：0x8500应答：0x8501
        /// 方向	Web，Vwas，HipCodec ->编码端
        /// 参数	HIPC_CMD_SIGNAL_SOURCE_SET_REQ 
        /// HIPC_CMD_SIGNAL_SOURCE_SET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	 head;
        ///      Uint8 dpOrDualLink; //0：dp信号  1: duallink信号
        /// } T_HIPC_SIGNAL_SELECT_REQ,T_HIPC_SIGNAL_SELECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SIGNAL_SOURCE_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SIGNAL_SELECT_REQ request = new T_HIPC_SIGNAL_SELECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8500 };
            T_HIPC_SIGNAL_SELECT_RESP response = handler.Handle<T_HIPC_SIGNAL_SELECT_RESP>(request);

            Assert.AreEqual(0x8501, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取信号源
        /// ID	请求：0x8502应答：0x8503
        /// 方向	Web，Vwas，HipCodec ->编码端
        /// 参数	HIPC_CMD_SIGNAL_SOURCE_GET_REQ
        /// HIPC_CMD_SIGNAL_SOURCE_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	 head;
        ///      Uint8 dpOrDualLink; //0：dp信号  1: duallink信号
        /// } T_HIPC_SIGNAL_SELECT_REQ,T_HIPC_SIGNAL_SELECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SIGNAL_SOURCE_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SIGNAL_SELECT_REQ request = new T_HIPC_SIGNAL_SELECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8502 };
            T_HIPC_SIGNAL_SELECT_RESP response = handler.Handle<T_HIPC_SIGNAL_SELECT_RESP>(request);

            Assert.AreEqual(0x8503, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取信号源分辨率
        /// ID	请求：0x8504应答：0x8505
        /// 方向	Web，Vwas，HipCodec ->编码端
        /// 参数	HIPC_CMD_SIGNAL_RESOLUTION_GET_REQ
        /// HIPC_CMD_SIGNAL_RESOLUTION_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8               channel;
        ///     Uint16             width;
        ///     Uint16             height;
        /// }T_HIPC_SIGNAL_RESOLUTION_REQ, T_HIPC_SIGNAL_RESOLUTION_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SIGNAL_RESOLUTION_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_SIGNAL_RESOLUTION_REQ request = new T_HIPC_SIGNAL_RESOLUTION_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8504 };
            T_HIPC_SIGNAL_RESOLUTION_RESP response = handler.Handle<T_HIPC_SIGNAL_RESOLUTION_RESP>(request);

            Assert.AreEqual(0x8505, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置EDID信息
        /// ID	请求：0x8506应答：0x8507
        /// 方向	Web，HipCodec ->编码端
        /// 参数	HIPC_CMD_SIGNAL_EDID_SET_REQ
        /// HIPC_CMD_SIGNAL_EDID_SET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER     head;
        ///     Uint8               count;  //设置EDID的数量 ，目前支持设置三个
        ///     Uint8 dpOrDualLink; //0：dp信号  1: duallink信号
        ///     T_EDID_RESOLUTION     edidInfo[EDID_SUPPORT_MAX];
        /// } T_HIPC_EDID_CONFIG_REQ, T_HIPC_EDID_CONFIG_RESP;
        /// typedef struct
        /// {
        ///     Uint16 width;  
        ///     Uint16 height; 
        ///     Uint8   hz;           //场频
        /// }T_EDID_RESOLUTION;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SIGNAL_EDID_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_EDID_CONFIG_REQ request = new T_HIPC_EDID_CONFIG_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8506 };
            T_HIPC_EDID_CONFIG_RESP response = handler.Handle<T_HIPC_EDID_CONFIG_RESP>(request);

            Assert.AreEqual(0x8507, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取EDID信息
        /// ID	请求：0x8508应答：0x8509
        /// 方向	Web， HipCodec ->编码端
        /// 参数	HIPC_CMD_SIGNAL_EDID_GET_REQ
        /// HIPC_CMD_SIGNAL_EDID_GET_RESP
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER     head;
        ///     Uint8       count;  //支持 EDID的数量     T_EDID_RESOLUTION
        ///      Uint8 dpOrDualLink; //0：dp信号  1: duallink信号
        ///      edidInfo[EDID_SUPPORT_MAX];
        /// } T_HIPC_EDID_CONFIG_REQ, T_HIPC_EDID_CONFIG_RESP;
        /// typedef struct
        /// {
        ///     Uint16 width;  //
        ///     Uint16 height; 
        ///     Uint8   hz;           //场频
        ///  }T_EDID_RESOLUTION;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_SIGNAL_EDID_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_EDID_CONFIG_REQ request = new T_HIPC_EDID_CONFIG_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8508 };
            T_HIPC_EDID_CONFIG_RESP response = handler.Handle<T_HIPC_EDID_CONFIG_RESP>(request);

            Assert.AreEqual(0x8509, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置图像质量等级 
        /// ID	请求：0x8600应答：0x8601
        /// 方向	Web，HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_LEVEL_SET_REQ
        /// HIPC_CMD_VIDEO_LEVEL_SET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8 channel;       
        ///     Uint8 level;  //0: HIGH  1: mIddle   2:low
        /// }T_HIPC_VIDEO_LEVEL_REQ,T_HIPC_VIDEO_LEVEL_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_LEVEL_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_LEVEL_REQ request = new T_HIPC_VIDEO_LEVEL_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8600 };
            T_HIPC_VIDEO_LEVEL_RESP response = handler.Handle<T_HIPC_VIDEO_LEVEL_RESP>(request);

            Assert.AreEqual(0x8601, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取图像质量等级 
        /// ID	请求：0x8602应答：0x8603
        /// 方向	Web， HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_LEVEL_GET_REQ
        /// HIPC_CMD_VIDEO_LEVEL_GET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8 channel;       
        ///     Uint8 level;  //0: HIGH  1: mIddle   2:low
        /// }T_HIPC_VIDEO_LEVEL_REQ,T_HIPC_VIDEO_LEVEL_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_LEVEL_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_LEVEL_REQ request = new T_HIPC_VIDEO_LEVEL_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8602 };
            T_HIPC_VIDEO_LEVEL_RESP response = handler.Handle<T_HIPC_VIDEO_LEVEL_RESP>(request);

            Assert.AreEqual(0x8603, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置图像码流大小
        /// ID	请求：0x8604应答：0x8605
        /// 方向	Web， HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_BITRATE_SET_REQ
        /// HIPC_CMD_VIDEO_BITRATE_SET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8 channel;       
        ///     Uint32 bitrate;     //（100000-50000000）100K-50M
        /// }T_HIPC_VIDEO_BITRATE_REQ,T_HIPC_VIDEO_BITRATE_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_BITRATE_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_BITRATE_REQ request = new T_HIPC_VIDEO_BITRATE_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8604 };
            T_HIPC_VIDEO_BITRATE_RESP response = handler.Handle<T_HIPC_VIDEO_BITRATE_RESP>(request);

            Assert.AreEqual(0x8605, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取图像码流大小
        /// ID	请求：0x8606应答：0x8607
        /// 方向	Web， HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_BITRATE_GET_REQ
        /// HIPC_CMD_VIDEO_BITRATE_GET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8 channel;       
        ///     Uint32 bitrate;
        /// }T_HIPC_VIDEO_BITRATE_REQ,T_HIPC_VIDEO_BITRATE_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_BITRATE_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_BITRATE_REQ request = new T_HIPC_VIDEO_BITRATE_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8606 };
            T_HIPC_VIDEO_BITRATE_RESP response = handler.Handle<T_HIPC_VIDEO_BITRATE_RESP>(request);

            Assert.AreEqual(0x8607, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置视频当前控制类型
        /// ID	请求：0x8608应答：0x8609
        /// 方向	Web，HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_CONTRL_TYPE_SET_REQ
        /// HIPC_CMD_VIDEO_CONTRL_TYPE_SET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER head;
        ///     Uint8 channel;
        ///     Uint8 rateControlType; // 0:VBR 1:CBR
        /// }T_HIPC_VIDEO_CONTROL_TYPE_REQ,T_HIPC_VIDEO_CONTROL_TYPE_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_CONTRL_TYPE_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_CONTROL_TYPE_REQ request = new T_HIPC_VIDEO_CONTROL_TYPE_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8608 };
            T_HIPC_VIDEO_CONTROL_TYPE_RESP response = handler.Handle<T_HIPC_VIDEO_CONTROL_TYPE_RESP>(request);

            Assert.AreEqual(0x8609, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取视频当前控制类型
        /// ID	请求：0x860a应答：0x860b
        /// 方向	Web，HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_CONTRL_TYPE_GET_REQ
        /// HIPC_CMD_VIDEO_CONTRL_TYPE_GET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER head;
        ///     Uint8 channel;
        ///     Uint8 rateControlType; // 0:VBR 1:CBR
        /// }T_HIPC_VIDEO_CONTROL_TYPE_REQ,T_HIPC_VIDEO_CONTROL_TYPE_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_CONTRL_TYPE_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_CONTROL_TYPE_REQ request = new T_HIPC_VIDEO_CONTROL_TYPE_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x860a };
            T_HIPC_VIDEO_CONTROL_TYPE_RESP response = handler.Handle<T_HIPC_VIDEO_CONTROL_TYPE_RESP>(request);

            Assert.AreEqual(0x860b, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取视频子码流
        /// ID	请求：0x860c应答：0x860d
        /// 方向	Vwas ->编码端
        /// 参数	HIPC_CMD_VIDEO_SUB_STREAM_CONNECT_REQ
        /// HIPC_CMD_VIDEO_SUB_STREAM_CONNECT_RESP
        /// Typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  channel;          //通道号
        ///     Uint8  ipAddress[20];    // 解码端自己的ip地址，后续如果有组播，则是组播地址。
        ///     Uint16  port;            //如果是tcp解码端使用该端口连接编码
        ///     Uint8  mode;            //视频发送方式 0:UDP组播 1: UDP 2: TCP 3:RTSP.
        /// } T_HIPC_VIDEO_CONNECT_REQ, T_HIPC_VIDEO_CONNECT_RESP;
        /// 注意：目前HIPC第一版的发送方式支持tcp和rtsp。
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_SUB_STREAM_CONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_CONNECT_REQ request = new T_HIPC_VIDEO_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x860c };
            T_HIPC_VIDEO_CONNECT_RESP response = handler.Handle<T_HIPC_VIDEO_CONNECT_RESP>(request);

            Assert.AreEqual(0x860d, response.head.msgType);
        }

        /// <summary>
        /// 消息		断开视频子码流
        /// ID	请求：0x860e应答：0x860f
        /// 方向	Vwas ->编码端
        /// 参数	HIPC_CMD_VIDEO_SUB_STREAM_DISCONNECT_REQ
        /// HIPC_CMD_VIDEO_SUB_STREAM_DISCONNECT_RESP
        /// Typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  channel;          //通道号
        ///     Uint8  ipAddress[20];    // 解码端自己的ip地址，后续如果有组播，则是组播地址。
        ///     Uint16  port;            //如果是tcp解码端使用该端口连接编码
        ///     Uint8  mode;            //视频发送方式 0:UDP组播 1: UDP 2: TCP 3:RTSP.
        /// } T_HIPC_VIDEO_CONNECT_REQ, T_HIPC_VIDEO_CONNECT_RESP;
        /// 注意：目前HIPC第一版的发送方式支持tcp和rtsp。
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_SUB_STREAM_DISCONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_CONNECT_REQ request = new T_HIPC_VIDEO_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x860e };
            T_HIPC_VIDEO_CONNECT_RESP response = handler.Handle<T_HIPC_VIDEO_CONNECT_RESP>(request);

            Assert.AreEqual(0x860f, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置子码流的分辨率
        /// ID	请求：0x8610应答：0x8611
        /// 方向	Vwas ->编码端
        /// 参数	HIPC_CMD_VIDEO_SUB_STREAM_RES_SET_REQ
        /// HIPC_CMD_VIDEO_SUB_STREAM_RES_SET_RESP
        /// Typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  channel;          //通道号
        ///     Uint8  type;             //0:QCIF 1CIF: 2:D1
        /// } T_HIPC_VIDEO_SUB_STREAM_RES_REQ, T_HIPC_VIDEO_SUB_STREAM_RES_RESP; 
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_SUB_STREAM_RES_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_SUB_STREAM_RES_REQ request = new T_HIPC_VIDEO_SUB_STREAM_RES_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8610 };
            T_HIPC_VIDEO_SUB_STREAM_RES_RESP response = handler.Handle<T_HIPC_VIDEO_SUB_STREAM_RES_RESP>(request);

            Assert.AreEqual(0x8611, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取子码流的分辨率
        /// ID	请求：0x8612应答：0x8613
        /// 方向	Vwas ->编码端
        /// 参数	HIPC_CMD_VIDEO_SUB_STREAM_RES_GET_REQ
        /// HIPC_CMD_VIDEO_SUB_STREAM_RES_GET_RESP
        /// Typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  channel;          //通道号
        ///     Uint8  type;             //0:QCIF 1CIF: 2:D1
        /// } T_HIPC_VIDEO_SUB_STREAM_RES_REQ, T_HIPC_VIDEO_SUB_STREAM_RES_RESP; 
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_SUB_STREAM_RES_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_SUB_STREAM_RES_REQ request = new T_HIPC_VIDEO_SUB_STREAM_RES_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8612 };
            T_HIPC_VIDEO_SUB_STREAM_RES_RESP response = handler.Handle<T_HIPC_VIDEO_SUB_STREAM_RES_RESP>(request);

            Assert.AreEqual(0x8613, response.head.msgType);
        }

        /// <summary>
        /// 消息		设置I帧间隔
        /// ID	请求：0x8614应答：0x8615
        /// 方向	Web， HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_GOP_SET_REQ
        /// HIPC_CMD_VIDEO_GOP_SET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8 channel;       
        ///     Uint16  keyFrameInterval ;   //I帧的间隔
        /// }T_HIPC_VIDEO_GOP_REQ,T_HIPC_VIDEO_GOP_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_GOP_SET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_GOP_REQ request = new T_HIPC_VIDEO_GOP_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8614 };
            T_HIPC_VIDEO_GOP_RESP response = handler.Handle<T_HIPC_VIDEO_GOP_RESP>(request);

            Assert.AreEqual(0x8615, response.head.msgType);
        }

        /// <summary>
        /// 消息		获取I帧间隔
        /// ID	请求：0x8616应答：0x8617
        /// 方向	Web， HipCodec ->编码端
        /// 参数	HIPC_CMD_VIDEO_GOP_GET_REQ
        /// HIPC_CMD_VIDEO_GOP_GET_RESP
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8 channel;       
        ///     Uint16  keyFrameInterval ;   //I帧的间隔
        /// }T_HIPC_VIDEO_GOP_REQ,T_HIPC_VIDEO_GOP_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_GOP_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_GOP_REQ request = new T_HIPC_VIDEO_GOP_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8616 };
            T_HIPC_VIDEO_GOP_RESP response = handler.Handle<T_HIPC_VIDEO_GOP_RESP>(request);

            Assert.AreEqual(0x8617, response.head.msgType);
        }
    }
}
